package thread.pipe_stream;

import java.io.IOException;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;

/**
 * Created by mHandler on 2018/6/2 0002.
 * Description:通过管道流进行线程间通信，读/写线程间信息交互
 */
public class PipeTest {

    public static void main(String[] args) {

        try {
            WriteData write = new WriteData();
            ReadData read = new ReadData();

            PipedInputStream inputStream = new PipedInputStream();
            PipedOutputStream outputStream = new PipedOutputStream();

            outputStream.connect(inputStream);

            ReadThread readThread = new ReadThread(read,inputStream);
            readThread.start();
            Thread.sleep(2000);

            WriteThread writeThread =new WriteThread(write,outputStream);
            writeThread.start();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
